package com.example.education.controller;

import com.example.education.exception.ParamException;
import com.example.education.model.Course;
import com.example.education.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class PageShowController {
    @Autowired
    private CourseService courseService;

    @RequestMapping("/page/loginPage")
    public String showLogin() {
        return "login";
    }

    @RequestMapping("/page/registerPage")
    public String showRegister() {
        return "register";
    }

    @RequestMapping("/")
    public String shoHome(Model model) {
        List<Course> courses = null;
        try {
            courses = courseService.getCourseByCateId(null, 0, 5);
            model.addAttribute("courses", courses);
        } catch (ParamException e) {
            e.printStackTrace();
        }
        return "home";
    }

    @RequestMapping("/admin")
    public String shoHome() {
        return "index";
    }

    @RequestMapping("/page/player")
    public String showPlayer(Model model, String path, Integer courseNum, Integer currentCourseNum) {
        model.addAttribute("path", path);
        model.addAttribute("courseNum", courseNum);
        if (currentCourseNum == null) {
            currentCourseNum = 1;
        }
        model.addAttribute("currentCourseNum", currentCourseNum);
        return "player";
    }

    @RequestMapping("/page/evaluate/list")
    public String showEvaluateList() {
        return "evaluate/list";
    }

    @RequestMapping("/page/course/list")
    public String showCourseList() {
        return "course/list";
    }
    @RequestMapping("/page/course/add")
    public String showCourseAdd() {
        return "course/add";
    }
    @RequestMapping("/page/course/addVideo")
    public String showCourseAddVideo(Model model,Integer courseId) {
        model.addAttribute("courseId",courseId);
        return "course/video-add";
    }
}
